//offer18 - 删除链表中的节点
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        if(head == null){
            return null;
        }
        if(head.val == val){
            head = head.next;
            return head;
        }
        ListNode cur = head;
        while(cur.next != null && cur.next.val != val){
            cur = cur.next;
        }
        if(cur.next != null){
            cur.next = cur.next.next;
        }
        return head;
    }
}
//offer24 - 反转链表
class Solution {
    public ListNode reverseList(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }
        ListNode prev = head;
        ListNode cur = head.next;
        while(cur != null){
            ListNode curNext = cur.next;
            cur.next = prev;
            prev = cur;
            cur = curNext;
        }
        head.next = null;
        return prev;
    }
}
//offer06 - 从头到尾打印链表
class Solution {
    ArrayList<Integer> tmp = new ArrayList<Integer>();
    public int[] reversePrint(ListNode head) {
        A(head);
        int[] ans = new int[tmp.size()];
        for(int i = 0; i<ans.length; i++){
            ans[i] = tmp.get(i);
        }
        return ans;
    }
    public void A(ListNode head){
        if(head == null){
            return;
        }
        A(head.next);
        tmp.add(head.val);
    }
}

public class Test {
}
